export WORK_DIR=/opt/local/mongo-cluster1
export KEYFILE=$WORK_DIR/keyfile/mongo.key
export CONF_NODE=$WORK_DIR/conf/mongo_node.conf
export CONF_ROUTER=$WORK_DIR/conf/mongos.conf
export MONGOD=$WORK_DIR/bin/mongod
export MONGO=$WORK_DIR/bin/mongo
export MONGOS=$WORK_DIR/bin/mongos
export PORT_CONFIG_1=26001
export PORT_CONFIG_2=26002
export PORT_CONFIG_3=26003
export PORT_SHARD1_1=27001
export PORT_SHARD1_2=27002
export PORT_SHARD1_3=27003
export PORT_SHARD2_1=27004
export PORT_SHARD2_2=27005
export PORT_SHARD2_3=27006
export PORT_MONGOS_1=25001
export PORT_MONGOS_2=25002
export PORT_MONGOS_3=25003

export ADMIN_DB=admin
export ADMIN_USER=admin
export ADMIN_PWD=admin@2016
export APP_DB=appdb
export APP_USER=appuser
export APP_PWD=appuser@2016

export CONF_NODE_STR='
storage:
    engine: wiredTiger
    directoryPerDB: true
    journal:
        enabled: true
systemLog:
    destination: file
    logAppend: true
operationProfiling:
  slowOpThresholdMs: 10000
replication:
    oplogSizeMB: 10240
processManagement:
    fork: true
net:
    http:
      enabled: false
security:
    authorization: "enabled"
'
export CONF_ROUTER_STR='
systemLog:
    destination: file
    logAppend: true
processManagement:
    fork: true
net:
    http:
      enabled: false
'
export REPL_CFG_CONFIG="
var cfg={
    _id:'configReplSet',
    configsvr: true,
    members:[
        {_id:0, host:'127.0.0.1:$PORT_CONFIG_1'},
        {_id:1, host:'127.0.0.1:$PORT_CONFIG_2'},
        {_id:2, host:'127.0.0.1:$PORT_CONFIG_3'}
    ]};
rs.initiate(cfg);
"
export REPL_CFG_SHARD1="
cfg={
    _id:'shard1',
    members:[
        {_id:0, host:'127.0.0.1:$PORT_SHARD1_1'},
        {_id:1, host:'127.0.0.1:$PORT_SHARD1_2'},
        {_id:2, host:'127.0.0.1:$PORT_SHARD1_3'}
    ]};
rs.initiate(cfg);
"
export REPL_CFG_SHARD2="
cfg={
    _id:'shard2',
    members:[
        {_id:0, host:'127.0.0.1:$PORT_SHARD2_1'},
        {_id:1, host:'127.0.0.1:$PORT_SHARD2_2'},
        {_id:2, host:'127.0.0.1:$PORT_SHARD2_3'}
    ]};
rs.initiate(cfg);
"
export MONGOS_CFG="
sh.addShard('shard1/127.0.0.1:$PORT_SHARD1_1')
sh.addShard('shard2/127.0.0.1:$PORT_SHARD2_1')
"

export ADMIN_INIT="
db = db.getSiblingDB('$ADMIN_DB');
db.createUser({
    user:'$ADMIN_USER',pwd:'$ADMIN_PWD',
    roles:[
        {role:'clusterAdmin',db:'$ADMIN_DB'},
        {role:'userAdminAnyDatabase',db:'$ADMIN_DB'},
        {role:'dbAdminAnyDatabase',db:'$ADMIN_DB'},
        {role:'readWriteAnyDatabase',db:'$ADMIN_DB'}
]})
"
export APP_INIT="
db = db.getSiblingDB('$ADMIN_DB');
db.auth('$ADMIN_USER','$ADMIN_PWD');
db = db.getSiblingDB('$APP_DB');
db.createUser({user:'$APP_USER',pwd:'$APP_PWD',roles:[{role:'dbOwner',db:'$APP_DB'}]})
sh.enableSharding('appdb')
"